package com.ktgj.train.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.train.domain.TrainOrderPayrecord;
import com.ktgj.train.service.ITrainOrderPayrecordService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 订单付款记录Controller
 * 
 * @author ruoyi
 * @date 2021-11-29
 */
@ControllerAdvice
@RestController
@RequestMapping("/payrecord")
public class TrainOrderPayrecordController extends BaseController
{
    @Autowired
    private ITrainOrderPayrecordService trainOrderPayrecordService;

    /**
     * 查询订单付款记录列表
     */
    @PreAuthorize(hasPermi = "train:payrecord:list")
    @GetMapping("/list")
    public TableDataInfo list(TrainOrderPayrecord trainOrderPayrecord)
    {
        startPage();
        List<TrainOrderPayrecord> list = trainOrderPayrecordService.selectTrainOrderPayrecordList(trainOrderPayrecord);
        return getDataTable(list);
    }

    /**
     * 导出订单付款记录列表
     */
    @PreAuthorize(hasPermi = "train:payrecord:export")
    @Log(title = "订单付款记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainOrderPayrecord trainOrderPayrecord) throws IOException
    {
        List<TrainOrderPayrecord> list = trainOrderPayrecordService.selectTrainOrderPayrecordList(trainOrderPayrecord);
        ExcelUtil<TrainOrderPayrecord> util = new ExcelUtil<TrainOrderPayrecord>(TrainOrderPayrecord.class);
        util.exportExcel(response, list, "订单付款记录数据");
    }

    /**
     * 获取订单付款记录详细信息
     */
    @PreAuthorize(hasPermi = "train:payrecord:query")
    @GetMapping(value = "/{recordid}")
    public AjaxResult getInfo(@PathVariable("recordid") Long recordid)
    {
        return AjaxResult.success(trainOrderPayrecordService.selectTrainOrderPayrecordById(recordid));
    }

    /**
     * 新增订单付款记录
     */
    @PreAuthorize(hasPermi = "train:payrecord:add")
    @Log(title = "订单付款记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainOrderPayrecord trainOrderPayrecord)
    {
        return toAjax(trainOrderPayrecordService.insertTrainOrderPayrecord(trainOrderPayrecord));
    }

    /**
     * 修改订单付款记录
     */
    @PreAuthorize(hasPermi = "train:payrecord:edit")
    @Log(title = "订单付款记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainOrderPayrecord trainOrderPayrecord)
    {
        return toAjax(trainOrderPayrecordService.updateTrainOrderPayrecord(trainOrderPayrecord));
    }

    /**
     * 删除订单付款记录
     */
    @PreAuthorize(hasPermi = "train:payrecord:remove")
    @Log(title = "订单付款记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordids}")
    public AjaxResult remove(@PathVariable Long[] recordids)
    {
        return toAjax(trainOrderPayrecordService.deleteTrainOrderPayrecordByIds(recordids));
    }
}
